package com.example.myapplication.activity

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.myapplication.R
import com.example.myapplication.databinding.ActivityMainBinding
import com.example.myapplication.fragment.IndexFragment
import com.example.myapplication.fragment.MyFragment
import com.example.myapplication.utils.GsonUtils
import com.example.myapplication.utils.NetUtils
import okhttp3.FormBody

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        binding.radioGroup.check(binding.radioGroup.getChildAt(0).id)
        var transaction = supportFragmentManager.beginTransaction()
        transaction.replace(R.id.frameLayout, IndexFragment()).commit()
        binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
            transaction = supportFragmentManager.beginTransaction()
            if (checkedId == binding.radioGroup.getChildAt(0).id) {
                transaction.replace(R.id.frameLayout, IndexFragment()).commit()
            } else {
                transaction.replace(R.id.frameLayout, MyFragment()).commit()
            }
        }
    }
}